package gov.pbc.nn.kjgl.gzjh.interceprot;

import gov.pbc.nn.kjgl.gzjh.dao.WorkDao;
import gov.pbc.nn.kjgl.gzjh.entity.WorkContent;
import gov.pbc.nn.kjgl.gzjh.entity.WorkPlanBanch;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.bstek.bdf2.export.interceptor.IDataInterceptor;

@Component("gzjhInterceptor")
public class GzjhInterceptor implements IDataInterceptor {
	@Autowired
	private WorkDao workkDao;
	
	@Override
	public String getName() {
		// TODO Auto-generated method stub
		return "gzjhInterceptor";
	}

	@Override
	public String getDesc() {
		// TODO Auto-generated method stub
		return "工作计划数据拼装";
	}

//	@Override
//	public void interceptGridData(List<Map<String, Object>> list) throws Exception {
//		// TODO Auto-generated method stub
//		for (Map<String, Object> singleData : list) {
//			String id=(String) singleData.get("id");
//			if(StringUtils.isNotBlank(id)){
//				List<WorkPlanBanch> workPlanBanchs = workkDao.getWorkPlanBanchById(id);
//				String temp="";
//				for(WorkPlanBanch wp:workPlanBanchs){
//					temp+=wp.getBanchCname()+"：\n";
//					List<WorkContent> workContents = workkDao.getWorkContentById(wp.getId());
//					int i=1;
//					for(WorkContent w:workContents){
//						temp+=i+"："+w.getWorkCompletionState()+"\n";
//						i++;
//					}
//					temp+="\n";
//				}
//				singleData.put("kzwcqk", temp);
//			}
//		}
//	}
	
	@Override
	public void interceptGridData(List<Map<String, Object>> list) throws Exception {
		// TODO Auto-generated method stub
		List<Map<String, Object>> tepmList=new ArrayList<Map<String,Object>>();
		for (Map<String, Object> singleData : list) {
			Map<String, Object> row = new HashMap<String, Object>();
			tepmList.add(row);
			String workname=(String) singleData.get("workName");
			String state=(String) singleData.get("state");
			String specificRequirement=(String) singleData.get("specificRequirement");
			String playDecompose=(String) singleData.get("playDecompose");
			Date endDate=(Date) singleData.get("endDate");
			Date startDate=(Date) singleData.get("startDate");
			row.put("workName", workname);
			row.put("state", state);
			row.put("specificRequirement", specificRequirement);
			row.put("playDecompose", playDecompose);
			row.put("endDate", endDate);
			row.put("startDate", startDate);
			String id=(String) singleData.get("id");
			if(StringUtils.isNotBlank(id)){
				List<WorkPlanBanch> workPlanBanchs = workkDao.getWorkPlanBanchById(id);
				for(WorkPlanBanch wp:workPlanBanchs){
					Map<String, Object> row2 = new HashMap<String, Object>();
					tepmList.add(row2);
					row2.put("kz", wp.getBanchCname());
//					temp+=wp.getBanchCname()+"：\n";
					List<WorkContent> workContents = workkDao.getWorkContentById(wp.getId());
//					int i=1;
					for(WorkContent w:workContents){
//						temp+=i+"："+w.getWorkCompletionState()+"\n";
//						i++;
						Map<String, Object> row3 = new HashMap<String, Object>();
						tepmList.add(row3);
						row3.put("kzwcqk", w.getWorkCompletionState());
					}
				}
			}
		}
		list.clear();
		list.addAll(tepmList);
	}

	@Override
	public void interceptAutoFormData(List<Map<String, Object>> list) throws Exception {
		// TODO Auto-generated method stub

	}

}
